//
//  EcgTipsView.m
//  CareRingApp
//
//  Created by Linktop on 2024/4/2.
//

#import "EcgTipsBaseView.h"

@implementation EcgTipsBaseView

-(instancetype)init
{
    if (self = [super init]) {
        [self addSubview:self.contentView];
        
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.closeBtn];
        [self layoutBase];
    }
    return self;
}


-(void)layoutBase
{
    self.backgroundColor = ITEM_BG_COLOR_ALPHA(0.7);
//    [self addSubview:self.contentView];
//    
//    
//    [self.contentView addSubview:self.titleLabel];
//    [self.contentView addSubview:self.closeBtn];
    
    CGFloat VOffset = 80;
    CGFloat hOffset = 20;

    [self.contentView mas_remakeConstraints:^(MASConstraintMaker *make) {
//        make.leading.equalTo(self.contentView.superview.mas_leading).offset(hOffset);
//        make.trailing.equalTo(self.contentView.superview.mas_trailing).inset(hOffset);
//        make.top.equalTo(self.contentView.superview.mas_top).offset(VOffset);
//        make.bottom.equalTo(self.contentView.superview.mas_bottom).inset(VOffset);
        
        make.centerX.equalTo(self.contentView.superview.mas_centerX);
        make.centerY.equalTo(self.contentView.superview.mas_centerY);
        make.width.equalTo(@335);
        make.height.equalTo(@507);
        
        
    }];
    
    [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.superview.mas_top).offset(5);
        make.centerX.equalTo(self.mas_centerX);
        make.height.greaterThanOrEqualTo(@30);
        make.width.lessThanOrEqualTo(self.titleLabel.superview.mas_width).multipliedBy(0.7);
    }];
    
    [self.closeBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_top);
        make.trailing.equalTo(self.closeBtn.superview.mas_trailing).inset(10);
    }];
    
}


-(void)closeClick:(QMUIButton *)btn {
    [self removeFromSuperview];
    if (self.closeBlk) {
        self.closeBlk();
    }
    
}

#pragma mark --lazy

-(UIView *)contentView
{
    if (!_contentView) {
        _contentView = [UIView new];
        _contentView.backgroundColor = UIColor.whiteColor;
    }
    return _contentView;
}
-(UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.numberOfLines = 0;
        _titleLabel.adjustsFontSizeToFitWidth = YES;
        _titleLabel.textColor = UIColor.darkGrayColor;
        _titleLabel.font = [UIFont fontWithName:FONT_ARIAL_BOLD size:18];
    }
    return _titleLabel;
}


-(QMUIButton *)closeBtn
{
    if (!_closeBtn) {
        _closeBtn = [[QMUIButton alloc]init];
        [_closeBtn setImage:[UIImage imageNamed:@"close_black"] forState:UIControlStateNormal];
        [_closeBtn addTarget:self action:@selector(closeClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _closeBtn;
}


@end
